package btcbot.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * TODO Comment
 *
 * @author mollagnier
 */
public class PropertyManager {

    private static final String FILE_PATH = "c:\\btcbot\\Bot2\\config.properties";

    private static Properties properties = null;

    /**
     * TODO Comment
     */
    private static void init(boolean reinit) {
        if (properties == null || reinit) {
            properties = new Properties();
            try {
                properties.load(new FileInputStream(FILE_PATH));
            }
            catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException("Error loading properties", e);
            }
        }
    }

    public static String get(String key) {
        init(false);
        return properties.getProperty(key);
    }

    public static Integer getInteger(String key) {
        String sInteger = get(key);
        return sInteger != null ? Integer.parseInt(sInteger) : null;
    }

    public static Boolean getBoolean(String key) {
        String sBoolean = get(key);
        return sBoolean != null ? Boolean.parseBoolean(sBoolean) : null;
    }
}